/*     */ package net.gxf.nehe.learn;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import java.nio.ByteBuffer;
/*     */ import java.nio.ByteOrder;
/*     */ import java.nio.IntBuffer;
/*     */ import org.lwjgl.input.Keyboard;
/*     */ import org.lwjgl.opengl.Display;
/*     */ import org.lwjgl.opengl.DisplayMode;
/*     */ import org.lwjgl.opengl.GL11;
/*     */ import org.lwjgl.util.glu.GLU;
/*     */ import org.newdawn.slick.opengl.Texture;
/*     */ import org.newdawn.slick.opengl.TextureLoader;
/*     */ import org.newdawn.slick.util.ResourceLoader;
/*     */ 
/*     */ public class Lesson11
/*     */ {
/*  44 */   private boolean done = false;
/*  45 */   private boolean fullscreen = false;
/*  46 */   private final String windowTitle = "NeHe's Lesson 11 (Flag Effect (Waving Texture))";
/*  47 */   private boolean f1 = false;
/*     */   private DisplayMode displayMode;
/*  50 */   private float[][][] points = new float[45][45][3];
/*  51 */   private int wiggle_count = 0;
/*     */   private float xrot;
/*     */   private float yrot;
/*     */   private float zrot;
/*     */   private float hold;
/*  58 */   private int[] texture = new int[1];
/*     */   private Texture textures;
/*     */ 
/*     */   public static void main(String[] args)
/*     */   {
/*  63 */     boolean fullscreen = false;
/*  64 */     if ((args.length > 0) && 
/*  65 */       (args[0].equalsIgnoreCase("fullscreen"))) {
/*  66 */       fullscreen = true;
/*     */     }
/*     */ 
/*  70 */     Lesson11 l11 = new Lesson11();
/*  71 */     l11.run(fullscreen);
/*     */   }
/*     */ 
/*     */   public void run(boolean fullscreen) {
/*  75 */     this.fullscreen = fullscreen;
/*     */     try {
/*  77 */       init();
/*  78 */       while (!this.done) {
/*  79 */         mainloop();
/*  80 */         render();
/*  81 */         Display.update();
/*     */       }
/*  83 */       cleanup();
/*     */     } catch (Exception e) {
/*  85 */       e.printStackTrace();
/*  86 */       System.exit(0);
/*     */     }
/*     */   }
/*     */ 
/*     */   private void mainloop() {
/*  91 */     if (Keyboard.isKeyDown(1)) {
/*  92 */       this.done = true;
/*     */     }
/*  94 */     if (Display.isCloseRequested()) {
/*  95 */       this.done = true;
/*     */     }
/*  97 */     if ((Keyboard.isKeyDown(59)) && (!this.f1)) {
/*  98 */       this.f1 = true;
/*  99 */       switchMode();
/*     */     }
/* 101 */     if (!Keyboard.isKeyDown(59))
/* 102 */       this.f1 = false;
/*     */   }
/*     */ 
/*     */   private void switchMode()
/*     */   {
/* 107 */     this.fullscreen = (!this.fullscreen);
/*     */     try {
/* 109 */       Display.setFullscreen(this.fullscreen);
/*     */     } catch (Exception e) {
/* 111 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   private void render()
/*     */   {
/* 119 */     GL11.glClear(16640);
/* 120 */     GL11.glLoadIdentity();
/*     */ 
/* 122 */     GL11.glTranslatef(0.0F, 0.0F, -12.0F);
/*     */ 
/* 124 */     GL11.glRotatef(this.xrot, 1.0F, 0.0F, 0.0F);
/* 125 */     GL11.glRotatef(this.yrot, 0.0F, 1.0F, 0.0F);
/* 126 */     GL11.glRotatef(this.zrot, 0.0F, 0.0F, 1.0F);
/*     */ 
/* 128 */     GL11.glBindTexture(3553, this.textures.getTextureID());
/*     */ 
/* 130 */     GL11.glBegin(7);
/* 131 */     for (int x = 0; x < 44; x++) {
/* 132 */       for (int y = 0; y < 44; y++) {
/* 133 */         float float_x = x / 44.0F;
/* 134 */         float float_y = y / 44.0F;
/* 135 */         float float_xb = (x + 1) / 44.0F;
/* 136 */         float float_yb = (y + 1) / 44.0F;
/*     */ 
/* 138 */         GL11.glTexCoord2f(float_x, float_y);
/* 139 */         GL11.glVertex3f(this.points[x][y][0], this.points[x][y][1], this.points[x][y][2]);
/*     */ 
/* 141 */         GL11.glTexCoord2f(float_x, float_yb);
/* 142 */         GL11.glVertex3f(this.points[x][(y + 1)][0], this.points[x][(y + 1)][1], this.points[x][(y + 1)][2]);
/*     */ 
/* 144 */         GL11.glTexCoord2f(float_xb, float_yb);
/* 145 */         GL11.glVertex3f(this.points[(x + 1)][(y + 1)][0], this.points[(x + 1)][(y + 1)][1], this.points[(x + 1)][(y + 1)][2]);
/*     */ 
/* 147 */         GL11.glTexCoord2f(float_xb, float_y);
/* 148 */         GL11.glVertex3f(this.points[(x + 1)][y][0], this.points[(x + 1)][y][1], this.points[(x + 1)][y][2]);
/*     */       }
/*     */     }
/* 151 */     GL11.glEnd();
/*     */ 
/* 153 */     if (this.wiggle_count == 2) {
/* 154 */       for (int y = 0; y < 45; y++) {
/* 155 */         this.hold = this.points[0][y][2];
/* 156 */         for (int x = 0; x < 44; x++) {
/* 157 */           this.points[x][y][2] = this.points[(x + 1)][y][2];
/*     */         }
/* 159 */         this.points[44][y][2] = this.hold;
/*     */       }
/* 161 */       this.wiggle_count = 0;
/*     */     }
/*     */ 
/* 164 */     this.wiggle_count += 1;
/*     */ 
/* 166 */     this.xrot += 0.3F;
/* 167 */     this.yrot += 0.2F;
/* 168 */     this.zrot += 0.4F;
/*     */   }
/*     */ 
/*     */   private void createWindow() throws Exception {
/* 172 */     Display.setFullscreen(this.fullscreen);
/* 173 */     DisplayMode[] d = Display.getAvailableDisplayModes();
/* 174 */     for (int i = 0; i < d.length; i++) {
/* 175 */       if ((d[i].getWidth() == 640) && (d[i].getHeight() == 480) && (d[i].getBitsPerPixel() == 32))
/*     */       {
/* 178 */         this.displayMode = d[i];
/* 179 */         break;
/*     */       }
/*     */     }
/* 182 */     Display.setDisplayMode(this.displayMode);
/* 183 */     Display.setTitle("NeHe's Lesson 11 (Flag Effect (Waving Texture))");
/* 184 */     Display.create();
/*     */   }
/*     */ 
/*     */   private void init() throws Exception {
/* 188 */     createWindow();
/*     */ 
/* 191 */     loadTextures();
/* 192 */     initGL();
/*     */ 
/* 194 */     for (int x = 0; x < 45; x++)
/* 195 */       for (int y = 0; y < 45; y++) {
/* 196 */         this.points[x][y][0] = (x / 5.0F - 4.5F);
/* 197 */         this.points[x][y][1] = (y / 5.0F - 4.5F);
/* 198 */         this.points[x][y][2] = ((float)Math.sin(x / 5.0D * 40.0D / 360.0D * 3.141592653589793D * 2.0D));
/*     */       }
/*     */   }
/*     */ 
/*     */   private void loadTextures() throws IOException
/*     */   {
/* 204 */     this.textures = loadTexture("Data/Tim.bmp");
/*     */   }
/*     */ 
/*     */   private void initGL() {
/* 208 */     GL11.glEnable(3553);
/* 209 */     GL11.glBlendFunc(770, 1);
/* 210 */     GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
/* 211 */     GL11.glClearDepth(1.0D);
/* 212 */     GL11.glDepthFunc(513);
/* 213 */     GL11.glEnable(2929);
/* 214 */     GL11.glShadeModel(7425);
/* 215 */     GL11.glMatrixMode(5889);
/* 216 */     GL11.glLoadIdentity();
/* 217 */     GLU.gluPerspective(45.0F, this.displayMode.getWidth() / this.displayMode.getHeight(), 0.1F, 100.0F);
/* 218 */     GL11.glMatrixMode(5888);
/* 219 */     GL11.glHint(3152, 4354);
/*     */ 
/* 221 */     GL11.glPolygonMode(1029, 6914);
/* 222 */     GL11.glPolygonMode(1028, 6913);
/*     */   }
/*     */ 
/*     */   private void cleanup() {
/* 226 */     Display.destroy();
/*     */   }
/*     */ 
/*     */   private final Texture loadTexture(String path) throws IOException {
/* 230 */     IntBuffer image = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
/*     */ 
/* 232 */     this.textures = TextureLoader.getTexture("BMP", ResourceLoader.getResourceAsStream(path));
/*     */ 
/* 237 */     ByteBuffer scratch = ByteBuffer.allocateDirect(this.textures.getImageWidth() * this.textures.getImageHeight() * 3);
/*     */ 
/* 241 */     IntBuffer buf = ByteBuffer.allocateDirect(12).order(ByteOrder.nativeOrder()).asIntBuffer();
/* 242 */     GL11.glGenTextures(buf);
/*     */ 
/* 244 */     GL11.glBindTexture(3553, buf.get(0));
/*     */ 
/* 248 */     GL11.glBindTexture(3553, buf.get(0));
/* 249 */     GL11.glTexParameteri(3553, 10240, 9728);
/* 250 */     GL11.glTexParameteri(3553, 10241, 9728);
/* 251 */     GL11.glTexImage2D(3553, 0, 6407, this.textures.getTextureWidth(), this.textures.getTextureHeight(), 0, 6407, 5121, scratch);
/*     */ 
/* 254 */     GL11.glBindTexture(3553, buf.get(1));
/* 255 */     GL11.glTexParameteri(3553, 10240, 9729);
/* 256 */     GL11.glTexParameteri(3553, 10241, 9729);
/* 257 */     GL11.glTexImage2D(3553, 0, 6407, this.textures.getTextureWidth(), this.textures.getTextureHeight(), 0, 6407, 5121, scratch);
/*     */ 
/* 260 */     GL11.glBindTexture(3553, buf.get(2));
/* 261 */     GL11.glTexParameteri(3553, 10240, 9729);
/* 262 */     GL11.glTexParameteri(3553, 10241, 9985);
/* 263 */     GLU.gluBuild2DMipmaps(3553, 3, this.textures.getImageWidth(), this.textures.getImageHeight(), 6407, 5121, scratch);
/*     */ 
/* 266 */     return this.textures;
/*     */   }
/*     */ }

/* Location:           C:\DBDownload\lwjglDemo2\lwjglDemo2\Run.jar
 * Qualified Name:     com.nehe.learn.Lesson11
 * JD-Core Version:    0.6.2
 */